#include <windows.h>

#include "lib.h"

#include "progconn.h"
#include "log.h"

#include "stdncerr.h"

// [AO 2007-06-08] Extracted Jackpot email notification to here
#include "smtp.h"

#ifdef DEBUG
static const String JACKPOT_NOTIFICATIONS = "casino-developers@riptownmedia.com";
static const String FUN_JACKPOT_NOTIFICATIONS = "casino-developers@riptownmedia.com";
#else
static const String JACKPOT_NOTIFICATIONS = "casino-JackpotNotifications@riptownmedia.com";
static const String FUN_JACKPOT_NOTIFICATIONS = "casino-FunJackpotNotifications@riptownmedia.com";
#endif

ProgressiveConnection::ProgressiveConnection(ProgressiveServer* server, SOCKET client)
	: Connection(server, client)
{
    jackpotID = -1;
    pProgServ = server;
}

ProgressiveConnection::~ProgressiveConnection()
{
}

bool8 ProgressiveConnection::isProgressiveOn()
{ 
    return pProgServ->isProgressiveOn(jackpotID);
}
int32 ProgressiveConnection::getProgressiveJackpot()
{
    return pProgServ->getProgressiveJackpot(jackpotID, getForRealFlag());
}

bool8 ProgressiveConnection::placeProgressiveBet(int32 betAmount, int32& multiBankBet)
{
    return pProgServ->placeProgressiveBet(jackpotID, 0, betAmount, 1, getForRealFlag(), getProgressiveFixedAmountMultiplier(), multiBankBet);
}

bool8 ProgressiveConnection::placeProgressiveBet(int32 betAmount, int32 betMultiplier, int32& multiBankBet)
{
    return pProgServ->placeProgressiveBet(jackpotID, 0, betAmount, betMultiplier, getForRealFlag(), getProgressiveFixedAmountMultiplier(), multiBankBet);
}

bool8 ProgressiveConnection::placeProgressiveContribution(int32 nContributionAmount, int32& multiBankBet)
{
    return pProgServ->placeProgressiveBet(jackpotID, nContributionAmount, 0, 1, getForRealFlag(), getProgressiveFixedAmountMultiplier(), multiBankBet);
}

void ProgressiveConnection::getProgressiveData(int32* jackpot, int32* rate)
{
	*jackpot = pProgServ->getProgressiveJackpot(jackpotID, getForRealFlag());
	*rate = 0; // [AO 2008-06-13] CSN-1818 - Let the client calculate the rate.
}

// kharmon.  10-05-05.  #5861.  Added bPercentage parameter so that a payrate of less than 100 can 
// optionally be treated as an absolute amount. 
bool8 ProgressiveConnection::setProgressiveWinner(int32 payrate, int32* payout, int32* multiBankPayout, bool bPercentage)
{
    return pProgServ->setProgressiveWinner(jackpotID, payrate, getForRealFlag(), getProgressiveFixedAmountMultiplier(), payout, multiBankPayout, bPercentage);
}

void ProgressiveConnection::setProgressiveOn(bool8 progressiveOn)
{
    pProgServ->setProgressiveOn(jackpotID, progressiveOn);
}

void ProgressiveConnection::setProgressiveJackpotID(int32 progJackpotID)
{
    jackpotID = progJackpotID;
    pProgServ->setProgressiveJackpotID(progJackpotID);
}

// [AO 2007-06-08] Extracted Jackpot email notification to here
void ProgressiveConnection::SendJackpotCandidateMail(String const& host_name,
													 String const& name_from,
													 String const& subject_suffix,
													 String const& message,
													 bool8 is_real)
{
	SMTP::Header hdr;
	hdr.bEmailAsHtml = false;
	hdr.nameFrom = name_from;
	hdr.nameFrom += " Jackpot Notice";

	if (is_real)
	{
		hdr.emailFrom = JACKPOT_NOTIFICATIONS;
		hdr.emailTo = JACKPOT_NOTIFICATIONS;
		hdr.subject = "Jackpot Candidate at ";
	}

	else // fun game
	{
		hdr.emailFrom = FUN_JACKPOT_NOTIFICATIONS;
		hdr.emailTo = FUN_JACKPOT_NOTIFICATIONS;
		hdr.subject = "Fun Jackpot Candidate at ";
	}

	hdr.subject += subject_suffix;

	SMTP::send(host_name, hdr, message);
}
